app.controller('NotifyListCtrl', function ($scope, ajax, $modal, $rootScope, toaster) {

	$scope.userid = $rootScope.loginUser.id;
	$scope.reload = $scope.page.loader('notify/' + $scope.userid + '/{pageIndex}/{pageSize}/20/page');
	$scope.$on('pageIndex', function (event, p) { $scope.reload(p); });
	$scope.reload(1);

	$scope.readAll = function () {
		var url = 'notify/' + $scope.userid + '/read/all';
		ajax.post(url, null, function (result) {
			if (result.code == 200) {
				$scope.reload($scope.bigCurrentPage);
				$scope.loadUnreadNotify($rootScope.loginUser.id);
			}
		}, function () { });
	};

	$scope.read = function (notify) {
		var url = 'notify/' + notify.id + '/read';
		ajax.post(url, null, function (result) {
			if (result.code == 200) {
				$scope.reload($scope.bigCurrentPage);
				$scope.loadUnreadNotify($rootScope.loginUser.id);
			}
		}, function () { });
	};

	$scope.del = function (size, current_data, submit_type) {
		var modalInstance = $scope.delModal(size, current_data, submit_type);
		modalInstance.result.then(function (param) {
			var url = '';
			if (param.type === 'delete') {
				url = 'notify/' + param.data.id + '/delete';
			} else if (param.type === 'deleteAll') {
				url = 'notify/' + $scope.userid + '/delete/all';
			}
			ajax.post(url, null, function (result) {
				if (result.code == 200) {
					$scope.reload($scope.bigCurrentPage);
					$scope.loadUnreadNotify($rootScope.loginUser.id);
				}
			}, function () { toaster.pop('error', '错误', '删除信息失败！'); });
		});
	};
});